"""
author= '李昊凌'
Create Time = 2020/7/1710:20
Change Time = 2020/7/18
commit:"车辆入口函数"
"""
import cv2
from datetime import datetime
from parking_database.query import query_all_parking_space
from parking_database.insert import input_entry_record,input_leave_record

from shibie.plate_recognition import plate_recodnition
def getEnterPlate(img_path):
    img=cv2.imread(img_path)
    plate = plate_recodnition(img)##识别车牌并返回车牌号码
    input_entry_record(plate)#将车牌信息上传到数据库
    dt=datetime.now()
    print(dt)




def recommand():#推荐车位，推荐最近的空车位
    row = [0,0,0,0,0]
    rows=['A','B','C','D','E']
    pcs = ['1','2','3','4','5']
    slots=query_all_parking_space()
    print(slots)
    recom=[]
    for i in range(0,5):
        for j in range(0,5):
            s=slots[i*5+j]['车牌']
            if s==None or '':
                row[i]+=1
                recom.append([i,j])
                break

    return "推荐停车位为"+rows[recom[0][0]]+pcs[recom[0][1]]
    # for i in (0,5):
    #     countnull=0
    #     for j in(0,5):
    #         if slots[i*5+j]!='null':
    #             row[i]+=1





if __name__ == "__main__":
    a=recommand()
    print(a)
    plate="云Q03538"
    time =input_leave_record(plate)
    print(time)

